class_name InteractiveBtn
extends Control

#region 属性
@onready var progress_bar: TextureProgressBar = %ProgressBar
@onready var key_label: Label = %KeyLabel
var _stay_time:float
var _default_scale:Vector2
var _tween:Tween
signal interact_completed(entity)
#endregion
#region 字段
#endregion
#region 信号
#endregion

#region 基类方法
#endregion
#region 公共方法
func init_interactive_btn(key:Key,stay_time:float):
	key_label.text = OS.get_keycode_string(key)
	_stay_time = stay_time
func start_interact(entity):
	if _tween and _tween.is_valid():
		return
	progress_bar.value = 0
	_tween = create_tween()
	_tween.tween_property(progress_bar,"value",1,_stay_time)
	_tween.parallel().tween_property(key_label.get_parent(),"scale",_default_scale * 0.9,_stay_time if _stay_time < 0.1 else 0.1)
	_tween.tween_callback(func ():
		interact_completed.emit(entity)
		end_interact(entity)
		)
func end_interact(entity):
	if _tween and _tween.is_valid():
		_tween.kill()
	key_label.get_parent().scale = _default_scale
	progress_bar.value = 0
#endregion
#region 私有方法
#endregion
#region 生命周期函数
func _ready() -> void:
	key_label.text = ""
	_default_scale = key_label.get_parent().scale
	progress_bar.value = 0
#endregion
